#include "inetaddress.hpp"
namespace moqi
{

InetAddress::InetAddress(const unsigned int &port, const string &ip)
{
    memset(&_add, 0, sizeof(_add));
    _add.sin_family = AF_INET;
    _add.sin_port = htons(port);
    _add.sin_addr.s_addr = inet_addr(ip.c_str());

}

InetAddress::InetAddress(const string &port, const string &ip)
{
    memset(&_add, 0, sizeof(_add));
    _add.sin_family = AF_INET;
    _add.sin_port = htons(stoi(port));
    _add.sin_addr.s_addr = inet_addr(ip.c_str());
}

InetAddress::InetAddress(const address_IPv4 & rhs)
:_add(rhs)
{

}

InetAddress::~InetAddress()
{

}

string InetAddress::ip()const
{
    return string(inet_ntoa(_add.sin_addr));
}

unsigned int InetAddress::port()const
{
    return ntohs(_add.sin_port);
}

const address_IPv4 * InetAddress::getInetAddress()const
{
    return &_add;
}

}


